/* ###################################################################
**     Filename    : GSPac_common.h
**     Project     : GSTF000004
**     Processor   : Active-Semi PAC5220
**     Author      : GSST
**     Version     : Driver 01.00
**     Compiler    : IAR C Compiler
**     Date/Time   : 2016-05-19, 19:47
**
** ###################################################################*/

#ifndef _GSPAC_COMMON_H
#define _GSPAC_COMMON_H

#include "stm32f4xx.h"
//#include "stm32f427xx.h"
#include "system_stm32f4xx.h"
// #include "stm32_assert_template.h"
// #include "stm32f4xx_rcc.h"
// #include "stm32f4xx_flash.h"
#define GS_IS_NEW_BROAD

#define GS_IS_NEW_ARM

#define GS_RAMFUNC //__ramfunc
#define GS_INLINE inline
#define     __IO    volatile
#ifdef _DEBUG
#define __VOLTAILE volatile
#else
#define __VOLTAILE
#endif

#define uint8 uint8_t
#define int8 int8_t
#define uint16 uint16_t
#define int16 int16_t
#define uint32 uint32_t
#define int32 int32_t
#define _IQ int32_t
#define _FLOAT float

#define BIT0 0x1
#define BIT1 0x2
#define BIT2 0x4
#define BIT3 0x8
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
#define BIT8 0x100
#define BIT9 0x200
#define BIT10 0x400
#define BIT11 0x800
#define BIT12 0x1000
#define BIT13 0x2000
#define BIT14 0x4000
#define BIT15 0x8000
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define BIT23 0x00800000
#define BIT24 0x01000000
#define BIT25 0x02000000
#define BIT26 0x04000000
#define BIT27 0x08000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000

#define NBIT0 0xFFFFFFFE
#define NBIT1 0xFFFFFFFD
#define NBIT2 0xFFFFFFFB
#define NBIT3 0xFFFFFFF7
#define NBIT4 0xFFFFFFEF
#define NBIT5 0xFFFFFFDF
#define NBIT6 0xFFFFFFBF
#define NBIT7 0xFFFFFF7F
#define NBIT8 0xFFFFFEFF
#define NBIT9 0xFFFFFDFF
#define NBIT10 0xFFFFFBFF
#define NBIT11 0xFFFFF7FF
#define NBIT12 0xFFFFEFFF
#define NBIT13 0xFFFFDFFF
#define NBIT14 0xFFFFBFFF
#define NBIT15 0xFFFF7FFF
#define NBIT16 0xFFFEFFFF
#define NBIT17 0xFFFDFFFF
#define NBIT18 0xFFFBFFFF
#define NBIT19 0xFFF7FFFF
#define NBIT20 0xFFEFFFFF
#define NBIT21 0xFFDFFFFF
#define NBIT22 0xFFBFFFFF
#define NBIT23 0xFF7FFFFF
#define NBIT24 0xFEFFFFFF
#define NBIT25 0xFDFFFFFF
#define NBIT26 0xFBFFFFFF
#define NBIT27 0xF7FFFFFF
#define NBIT28 0xEFFFFFFF
#define NBIT29 0xDFFFFFFF
#define NBIT30 0xBFFFFFFF
#define NBIT31 0x7FFFFFFF

#define GS_FALSE 0
#define GS_TRUE 1
#define GS_CCW GS_FALSE
#define GS_CW GS_TRUE

#define RECORD_LEN 10
#define RECORD_LENX 10
#define _BOOL uint8_t
#define _CONST const

//#define GS_TESTBENCH

#define NULL          _NULL

#define LOCALID 0x01 // Modbus ID, fixed
 
#define GS_ASM_NOP __ASM("nop")

#define APP_SHA_ORIG_DEFAULT_LEN 4

typedef struct{
    int16_t d_dataA[RECORD_LEN];
    int16_t d_dataB[RECORD_LEN];/*
    _FLOAT d_dataC[RECORD_LEN];
    _FLOAT d_dataD[RECORD_LEN];
    int16_t d_dataE[RECORD_LEN];
    int16_t d_dataF[RECORD_LEN];
    //int16_t d_dataG[RECORD_LEN];*/
    //int32_t d_dataH[RECORD_LEN];
    //int32_t d_dataI[RECORD_LEN];
    //int32_t d_dataJ[RECORD_LEN];
    //int32_t d_dataK[RECORD_LEN];
    //int32_t d_dataL[RECORD_LEN];
    //int32_t d_dataM[RECORD_LEN];
    uint16_t d_recordIndex;
} _DATA_RECORD;

typedef struct{
    int32_t d_dataA[RECORD_LENX];
    //int32_t d_dataB[RECORD_LENX];
    //int32_t d_dataC[RECORD_LENX];
    //int32_t d_dataD[RECORD_LENX];
    //int32_t d_dataE[RECORD_LENX];
    //int32_t d_dataF[RECORD_LENX];
    //int32_t d_dataG[RECORD_LENX];
    //int32_t d_dataH[RECORD_LENX];
    //int32_t d_dataI[RECORD_LENX];
    //int32_t d_dataJ[RECORD_LENX];
    //int32_t d_dataK[RECORD_LENX];
    //int32_t d_dataL[RECORD_LENX];
    //int32_t d_dataM[RECORD_LENX];
    uint16_t d_recordIndex;
} _DATA_RECORDX;

typedef struct{
    _FLOAT d_k;
    _FLOAT d_b;
} _COMM_LINE_KB;

extern uint16_t g_uid[4];

extern _DATA_RECORD g_dataRecord;

extern _DATA_RECORD g_dataRecordA;
extern _DATA_RECORD g_dataRecordB;

extern _DATA_RECORDX g_dataRecordXA;
extern _DATA_RECORDX g_dataRecordXB;

extern void g_COMMgetLineKB(_COMM_LINE_KB* l_kbPtr, _FLOAT l_x1, _FLOAT l_y1, _FLOAT l_x2, _FLOAT l_y2);
extern void g_memCpy(void* l_srcOrigPtr, void* l_dstOrigPtr, uint16_t l_len);
extern void g_memClr(void* l_dstOrigPtr, uint16_t l_len);
extern void g_usDelay(uint32_t l_usDelay);
extern uint16_t g_getCrc16(void* l_origPtr, uint16_t len);
extern uint16_t g_getCrc16X(const void* l_origPtr, uint16_t len);
extern uint8_t g_getXor(const void* l_origPtr, uint16_t l_len);
extern GS_RAMFUNC _IQ g_COMMnewtonSqurtRoot(_IQ l_squrt);


#endif
